require("../../assets/css/basic.css");
require("../../assets/css/normalize.css");
require("../../assets/css/reset.css");
require("./mine_badges.less");
//引入模块
const dom = require("../../utils/dom.js");
const axios = require("../../utils/axios.js");

document.addEventListener("DOMContentLoaded", function () {
	//回到上一页
	dom.get(".goback").addEventListener("click", function () {
		history.back();
	});
	//获取排名;
	axios.get("/api/user/info").then(function (res) {
		dom.get(".rank").textContent = res.data.data.ranking;
	});
	async function getBadge() {
		let badgeArr = [
			require("../../assets/images/mybadge01.jpg"),
			require("../../assets/images/mybadge02.jpg"),
			require("../../assets/images/mybadge03.jpg"),
			require("../../assets/images/mybadge04.jpg"),
			require("../../assets/images/mybadge05.jpg"),
			require("../../assets/images/mybadge06.jpg"),
			require("../../assets/images/mybadge07.jpg"),
			require("../../assets/images/mybadge08.jpg"),
		];
		let lastImg = require("../../assets/images/mybadge09.jpg");
		//发送请求获取徽章数据;
		let res = await axios.get("/api/exercise/badge");
		res.data.data.forEach(function (v) {
			dom.get("#badges ul").innerHTML += `
		                <li>
		                    <img src="${badgeArr[v.id - 1]}" alt="" />
		                    <span>${v.name}</span>
		                </li>
						`;
		});
		let lastLi = `
		<li>
		    <img src="${lastImg}" alt="" />
		</li>`;
		dom.get("#badges ul").innerHTML += lastLi;
	}
	getBadge();
});
